package org.dant.ant.extension.tasks;

import java.io.*;
import java.util.*;

import org.dant.ant.extension.tasks.commands.CopyCommand;
import org.dant.ant.extension.tasks.internal.Endpoint;

public class RemoteCopy extends RemoteTask {

    protected String srcdir;
    protected String destdir;
    protected String filename;
    protected String filetype;
    protected String rename;
  
    public RemoteCopy() {
        rcmd = new CopyCommand();
    }

    public void setCopyCommand(CopyCommand cmd) {
        this.rcmd = cmd;
    }

    public void setRename(String r) {
        this.rename = r;
    }
    public String getRename() {
        return this.rename;
    }
  
    public void setSrcdir(String dir) {
        this.srcdir = dir;
    }
  
    public void setDestdir(String dir) {
        this.destdir = dir;
    }
  
    public void setFilename(String f) {
        this.filename = f;
    }
  
    public void setFiletype(String t) {
        this.filetype = t;
    }

    public String getSrcdir() {
        return this.srcdir;
    }

    public String getDestdir() {
        return this.destdir;
    }

    public String getFilename() {
        return this.filename;
    }

    public String getFiletype() {
        return this.filetype;
    }
  
    public void resolveDir() throws IOException {
        for (Iterator iter = destHosts.keySet().iterator(); iter.hasNext();) {
            Endpoint ep = (Endpoint) iter.next();
            CopyCommand request = (CopyCommand)destHosts.get(ep);
            File basedir = ep.getBaseDir();
            File destDir = new File(request.getFullDestPath());
            if (basedir == null || destDir.isAbsolute()) {
                continue;
            }
            File absolutePath = fu.resolveFile(basedir, request.getFullDestPath());
            request.appendParameters("fulldestpath", absolutePath.getCanonicalPath());
        }
    }
}
